<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>在线考试平台</title>
    <link rel="shortcut icon" href="../images/exam.png" type="image/x-icon">
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/xadmin.css">

</head>

<body class="index">
<div class="container">
    <div class="logo">
        <a href="#">在线考试平台</a>
    </div>
    <ul class="layui-nav left" lay-filter="user_head">
        <li class="layui-nav-item"><a href="/exam_system/online_exam">在线考试</a></li>
        <li class="layui-nav-item"><a href="/exam_system/online_test">在线测试</a></li>
        <li class="layui-nav-item"><a href="/exam_system/score">我的成绩</a></li>
        <li class="layui-nav-item"><a href="/exam_system/error_question">我的错题</a></li>
        <li class="layui-nav-item"><a href="/exam_system/resources_library">资源库</a></li>
    </ul>
    <ul class="layui-nav right" lay-filter="header-user" id="user-state">

    </ul>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-sm12 layui-col-md10 layui-col-md-offset1">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-row layui-col-space15" style="background: #f7f8fc" id="error_question_list">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

</body>
<script type="text/javascript"  src="../lib/layui/layui.js"></script>
<script type="text/javascript" src="../js/xadmin.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script>
    layui.use(['element', "form", 'jquery', 'layer'], function () {
        const form = layui.form;
        const $ = layui.jquery;
        const layer = layui.layer;
        const element = layui.element;
        header(element)
        get_error_question_by_u_id()
    });

    function header(element) {
        var user_json = JSON.parse(sessionStorage.getItem("userJson"));
        var text = ""
        if (user_json === null) {
            location.href = '/exam_system';
        } else {
            text += "<li class=\"layui-nav-item\">" +
                "                    <a href=\"javascript:;\">" + user_json.u_name + "</a>" +
                "                    <dl class=\"layui-nav-child\">" +
                "                        <dd><a onclick='modify_psw()'>修改密码</a></dd>" +
                "                        <dd><a onclick='user_quit()'>退出</a></dd>" +
                "                    </dl>" +
                "                </li>"
            $("#user-state").html(text)
        }
        element.render('header-user')
    }

    function user_quit() {
        sessionStorage.clear("userJson");
        location.href = '/exam_system';
    }

    function modify_psw() {
        layui.use(['element', "form", 'jquery', 'layer'], function () {
            const form = layui.form;
            const $ = layui.jquery;
            const layer = layui.layer;
            const element = layui.element;
            var text = "<form class=\"layui-form layui-form-pane\" action=\"\">" +
                "    <div class=\"layui-form-item\">" +
                "        <label class=\"layui-form-label\">旧密码</label>" +
                "        <div class=\"layui-input-block\">" +
                "            <input type=\"text\" name=\"o_psw\" id='o_psw' autocomplete=\"off\" placeholder=\"请输入旧密码\"" +
                "                   class=\"layui-input\">" +
                "        </div>" +
                "    </div>" +
                "    <div class=\"layui-form-item\">" +
                "        <label class=\"layui-form-label\">新密码</label>" +
                "        <div class=\"layui-input-block\">" +
                "            <input type=\"password\" name=\"n_psw\" id='n_psw' autocomplete=\"off\" placeholder=\"请输入新密码\"" +
                "                   class=\"layui-input\">" +
                "        </div>" +
                "    </div>" +
                "    <div class=\"layui-form-item\">" +
                "        <label class=\"layui-form-label\">确认新密码</label>" +
                "        <div class=\"layui-input-block\">" +
                "            <input type=\"password\" name=\"re_psw\" id='re_psw' autocomplete=\"off\" placeholder=\"请输入确认密码\"" +
                "                   class=\"layui-input\">" +
                "        </div>" +
                "    </div>" +
                "</form>"
            var index = layer.open({
                type: 1,
                title: "修改密码",
                closeBtn: 1,
                shadeClose: true,
                btn: '确定',
                yes: function (index, layero) {
                    var o_psw = $("#o_psw").val();
                    var n_psw = $("#n_psw").val();
                    var re_psw = $("#re_psw").val();
                    var user_json = JSON.parse(sessionStorage.getItem("userJson"));
                    var u_psw=user_json.u_psw;
                    var u_id=user_json.u_id;
                    if (u_psw!==o_psw){
                        layer.msg("旧密码错误 请重新输入", {icon: 5, time: 1000});
                        return false;
                    }
                    if (n_psw !== re_psw) {
                        layer.msg("两次密码不一致", {icon: 5, time: 1000});
                        return false;
                    }
                    $.ajax({
                        url: 'update_user_psw_by_u_id',
                        dataType: "json",//数据格式
                        type: "post",//请求方式
                        cache: false,
                        data: {
                            u_id: u_id,
                            u_psw: n_psw,
                        },
                        success: function (data) {
                            if (data.code === 200) {
                                layer.msg(data.message, {icon: 6}, function () {
                                    sessionStorage.clear("userJson");
                                    location.href = '/exam_system';
                                });
                            } else {
                                layer.msg(data.message, {icon: 5, time: 1000});
                            }
                        },
                        error: function (e) {
                            alert("出现错误！！");
                        }
                    });
                },
                area: ['500px', '400px'],
                content: text
            });
        });
    }


    function get_error_question_by_u_id() {
        layui.use(['layer', 'form'], function () {
            var user_json = JSON.parse(sessionStorage.getItem("userJson"));
            var u_id = user_json.u_id;
            $.ajax({
                url: 'get_error_question_by_u_id',
                dataType: "json",//数据格式
                type: "post",//请求方式
                async: false,//是否异步请求
                data: {u_id: u_id},
                success: function (data) {
                    if (data.code === 200) {
                        var text = "";
                        for (let i = 0; i < data.result.length; i++) {
                            var q_type = data.result[i].q_type;
                            if (q_type === "单选") {
                                text += "<div class=\"layui-col-sm12\" style=\"background: #f7f8fc\">" +
                                    "                            <div class=\"layui-card\">" +
                                    "                                <div class=\"layui-card-header\" style='background: gainsboro'>" +
                                    "                                    单选题" +
                                    "                                </div>" +
                                    "                               <div class=\"layui-card-header\">" +
                                    "<span style='float: right'><a class=\"layui-btn layui-btn-normal layui-btn-sm\" onclick=\"del_error_question(" + data.result[i].eq_id + ")\">移除错题集</a></span>" +
                                    "                                       <xmp>" + (i + 1) + "." + data.result[i].objects.c_describe + "</xmp>" +
                                    "                                    </div>" +
                                    "                                    <div class=\"layui-card-header\">" +
                                    "                                        <xmp>A:" + data.result[i].objects.c_a + "</xmp>" +
                                    "                                    </div>" +
                                    "                                    <div class=\"layui-card-header\">" +
                                    "                                        <xmp>B:" + data.result[i].objects.c_b + "</xmp>" +
                                    "                                    </div>" +
                                    "                                    <div class=\"layui-card-header\">" +
                                    "                                        <xmp>C:" + data.result[i].objects.c_c + "</xmp>" +
                                    "                                    </div>" +
                                    "                                    <div class=\"layui-card-header\">" +
                                    "                                        <xmp>D:" + data.result[i].objects.c_d + "</xmp>" +
                                    "                                    </div>" +
                                    "                                    <div class=\"layui-card-header\">正确答案:" +
                                    "                                        " + data.result[i].objects.c_answer + "" +
                                    "                                    </div>" +
                                    "                                    <div class=\"layui-card-body\">答案解析:" +
                                    "" + data.result[i].objects.c_analysis + "" +
                                    "                                    </div>" +
                                    "                            </div>" +
                                    "                        </div>";
                            } else if (q_type === "判断") {
                                text += "<div class=\"layui-col-sm12\" style=\"background: #f7f8fc\">" +
                                    "                            <div class=\"layui-card\">" +
                                    "                                <div class=\"layui-card-header\" style='background: gainsboro'>" +
                                    "                                    判断题" +
                                    "                                </div>" +
                                    "                                <div class=\"layui-card-header\">" +
                                    "<span style='float: right'><a class=\"layui-btn layui-btn-normal layui-btn-sm\" onclick=\"del_error_question(" +data.result[i].eq_id +  ")\">移除错题集</a></span>" +
                                    "                                    <xmp>" + (i + 1) + "." + data.result[i].objects.j_describe + "</xmp>" +
                                    "                                </div>" +
                                    "                                    <div class=\"layui-card-header\">正确答案:" +
                                    "                                        " + data.result[i].objects.j_answer + "" +
                                    "                                    </div>" +
                                    "                                    <div class=\"layui-card-body\">答案解析:" +
                                    "" + data.result[i].objects.j_analysis + "" +
                                    "                                    </div>" +
                                    "                            </div>" +
                                    "                        </div>";
                            }  else if (q_type === "填空") {
                                text += "<div class=\"layui-col-sm12\" style=\"background: #f7f8fc\">" +
                                    "                            <div class=\"layui-card\" >" +
                                    "                                <div class=\"layui-card-header\" style='background: gainsboro'>" +
                                    "                                    填空题" +
                                    "                                </div>" +
                                    "                                <div class=\"layui-card-header\">" +
                                    "<span style='float: right'><a class=\"layui-btn layui-btn-normal layui-btn-sm\" onclick=\"del_error_question(" + data.result[i].eq_id +  ")\">移除错题集</a></span>" +
                                    "                                    <xmp>" + (i + 1) + "." + data.result[i].objects.fb_describe + "</xmp>" +
                                    "                                </div>" +
                                    "                                    <div class=\"layui-card-body\">正确答案:" +
                                    "" + data.result[i].objects.fb_answer + "" +
                                    "                                    </div>" +
                                    "                                    <div class=\"layui-card-body\">答案解析:" +
                                    "" + data.result[i].objects.fb_analysis + "" +
                                    "                                    </div>" +
                                    "                            </div>" +
                                    "                        </div>";
                            }else if (q_type === "简答") {
                                text += "<div class=\"layui-col-sm12\" style=\"background: #f7f8fc\">" +
                                    "                            <div class=\"layui-card\" >" +
                                    "                                <div class=\"layui-card-header\" style='background: gainsboro'>" +
                                    "                                    简答题" +
                                    "                                </div>" +
                                    "                                <div class=\"layui-card-header\">" +
                                    "<span style='float: right'><a class=\"layui-btn layui-btn-normal layui-btn-sm\" onclick=\"del_error_question(" + data.result[i].eq_id +  ")\">移除错题集</a></span>" +
                                    "                                    <xmp>" + (i + 1) + "." + data.result[i].objects.sa_describe + "</xmp>" +
                                    "                                </div>" +
                                    "                                    <div class=\"layui-card-body\">正确答案:" +
                                    "" + data.result[i].objects.sa_answer + "" +
                                    "                                    </div>" +
                                    "                                    <div class=\"layui-card-body\">答案解析:" +
                                    "" + data.result[i].objects.sa_analysis + "" +
                                    "                                    </div>" +
                                    "                            </div>" +
                                    "                        </div>";
                            }

                        }
                        $("#error_question_list").html(text);
                    } else {

                    }
                },
                error: function (e) {
                    alert("出现错误！！");
                }
            });
        })
    }

    function del_error_question(eq_id){
        layui.use(['layer', 'form'], function () {
            const layer = layui.layer;
            layer.confirm('确定移除?', {icon: 0}, function () {
                $.ajax({
                    url: 'del_error_question_by_eq_id',
                    dataType: "json",//数据格式
                    type: "post",//请求方式
                    async: false,//是否异步请求
                    data: {
                        eq_id: Number(eq_id)
                    },
                    success: function (data) {
                        if (data.code === 200) {
                            layer.msg(data.message, {icon: 6},function (){
                                get_error_question_by_u_id()
                            })
                        } else {
                            layer.msg(data.message, {icon: 5, time: 1000})
                        }
                    },
                    error: function (e) {
                        alert("出现错误！！");
                    }
                });
            })
        })
    }
</script>

</html>